<script>
	// <!--
	
	function hapus(id,tab){
		$.ajax({
			url : "c_setup",
			data : {id : id, task : 'DELETE',tab : tab},
			type : 'POST'
		}).done(function(response){
			if (tab == "pic")
			gridStaff.trigger('reloadGrid');
			else
			gridOwner.trigger('reloadGrid');
			
		});
	}

	
	function edit(id,tab){
		if (tab == "pic"){
			$.ajax({
				url : "c_setup",
				data : {id : id, task : 'LIST_PIC', option : 'single'},
				type : 'POST',
				dataType : 'JSON'
			}).done(function(response){
				txtStafid.val(response[0].pic_id);
				txtNama.val(response[0].pic_name);
				if(response[0].pic_active == "Y") checkAktif.attr('checked', true); 
					else checkCr.attr('checked', false);
			});
		}else{
			$.ajax({
				url : "c_setup",
				data : {id : id, task : 'LIST_OWNER', option : 'single'},
				type : 'POST',
				dataType : 'JSON'
			}).done(function(response){
				txtOwnerid.val(response[0].owner_id);
				txtOwnernama.val(response[0].owner_nama);
				cmbJenis.val(response[0].owner_jenis);
				if(response[0].owner_aktif == "Y") checkOwneraktif.attr('checked', true); 
					else checkCr.attr('checked', false);
			});
		}
	}
		
	$(function(){
		/* declarisasi */
		gridStaff = $("#grid-staff");
		gridOwner = $("#grid-owner");
		
		txtRefresh = $("#txt-refresh");
		btnSimpanrefresh = $("#btn-simpanrefresh");
		btnResetrefresh = $("#btn-resetrefresh");
		formRefresh = $("#form-refresh");
		
		txtubahpassword = $("#txt-ubahpassword");
		txtubahpasswordrepeat = $("#txt-ubahpasswordrepeat");
		btnSimpanubahpassword = $("#btn-simpanubahpassword");
		formubahpassword = $("#form-ubahpassword");
		
		txtMerah = $("#txt-merah");
		txtKuning = $("#txt-kuning");
		txtHijau = $("#txt-hijau");
		btnSimpanrange = $("#btn-simpanrange");
		btnResetrange = $("#btn-resetrange");
		formRange = $("#form-range");
		
		txtStafid = $("#txt-stafid");
		txtNama = $("#txt-nama");
		checkAktif = $("#check-aktif");
		btnSimpanstaf = $("#btn-simpanstaf");
		btnResetstaf= $("#btn-resetstaf");
		formStaf= $("#form-staf");
		
		txtOwnerid = $("#txt-ownerid");
		txtOwnernama = $("#txt-ownernama");
		cmbJenis = $("#cmb-jenis");
		checkOwneraktif = $("#check-owneraktif");
		btnSimpanowner = $("#btn-simpanowner");
		btnResetowner= $("#btn-resetowner");
		formowner= $("#form-owner");
		
		/* make component */
		gridStaff.jqGrid({ 
			ajaxGridOptions : {type:"POST"},
			serializeGridData : function(postdata) { return postdata; },
			postData : {
				task :  'LIST_PIC'
			},
			url:'c_setup',
			datatype: "json", 
			colNames:['Nama Staff','Aktif','Action'],
			colModel:[ 
				{name:'pic_name',index:'pic_name', search : true},
				{name:'pic_active',index:'pic_active', search : false},
				{name:'action',index:'action', search : false}
			],
			rowNum:10, 
			rowList:[10,20,30], 
			pager: '#pgrid-staff', 
			sortname: 'id', 
			viewrecords: true, 
			sortorder: "desc",
			caption:"Daftar Staff" 
		}); 
		gridStaff.jqGrid('navGrid','#pgrid-staff',{edit:false,add:false,del:false,search:false});
		gridStaff.jqGrid('filterToolbar',{});
		
		gridOwner.jqGrid({ 
			ajaxGridOptions : {type:"POST"},
			serializeGridData : function(postdata) { return postdata; },
			postData : {
				task :  'LIST_OWNER'
			},
			url:'c_setup',
			datatype: "json", 
			colNames:['Nama owner','Jenis','Aktif','Action'],
			colModel:[ 
				{name:'owner_nama',index:'owner_nama', search : true},
				{name:'owner_jenis',index:'owner_jenis', search : false},
				{name:'owner_aktif',index:'owner_aktif', search : false},
				{name:'action',index:'action', search : false}
			],
			rowNum:10, 
			rowList:[10,20,30], 
			pager: '#pgrid-owner', 
			sortname: 'id', 
			viewrecords: true, 
			sortorder: "desc",
			caption:"Daftar owner" 
		}); 
		gridOwner.jqGrid('navGrid','#pgrid-owner',{edit:false,add:false,del:false,search:false});
		gridOwner.jqGrid('filterToolbar',{});
		
		/* event */
		btnResetrefresh.click(function(){
			$.ajax({
				url		: 'c_setup',
				type	: 'POST',
				dataType:"JSON",
				data	: {
					task : "GET_PARAM",
					param : "REFRESH"
				}
			}).done(function(response){
				txtRefresh.val(response[0].nvalue1);
			
			});
		});
		
		btnResetrange.click(function(){
			$.ajax({
				url		: 'c_setup',
				type	: 'POST',
				dataType:"JSON",
				data	: {
					task : "GET_PARAM"
				}
			}).done(function(response){
				for(i=0;i<response.length;i++){
					if (response[i].param1 == "MERAH") txtMerah.val(response[i].nvalue1);
					else if (response[i].param1 == "KUNING") txtKuning.val(response[i].nvalue1);
					else if (response[i].param1 == "HIJAU") txtHijau.val(response[i].nvalue1);
				}
			});
		});
		
		btnSimpanrange.click(function(){
			data = formRange.serializeObject();
			$.ajax({
				url : "c_setup",
				data : data,
				type : 'POST'
			});
		});
		
		btnSimpanrefresh.click(function(){
			data = formRefresh.serializeObject();
			$.ajax({
				url : "c_setup",
				data : data,
				type : 'POST'
			});
		});
		
		btnSimpanubahpassword.click(function(){
			
			passwordNew = txtubahpassword.val();
			passwordRepeat = txtubahpasswordrepeat.val();
			if (passwordNew == ""){
				alert("Password tidak boleh kosong!");
			}else if(passwordNew != passwordRepeat){
				alert("Password tidak sama!");
			}else{			
				$.ajax({
					url : "c_setup",
					data : {task : "UBAH_PASSWORD",password : passwordNew},
					type : 'POST'
				}).done(function(response){
					if (response == "1"){
						alert("Password berhasil disimpan!");
					}
				});
			}
		});
		
		btnSimpanstaf.click(function(){
			data = formStaf.serializeObject();
			$.ajax({
				url : "c_setup",
				data : data,
				type : 'POST'
			}).done(function(){
				btnResetstaf.click();
				gridStaff.trigger('reloadGrid');
			});
		});
		
		btnSimpanowner.click(function(){
			data = formowner.serializeObject();
			$.ajax({
				url : "c_setup",
				data : data,
				type : 'POST'
			}).done(function(){
				btnResetowner.click();
				gridOwner.trigger('reloadGrid');
			});
		});
		
		/* method started */
		btnResetrange.click();
		btnResetrefresh.click();
	});
	// -->
</script>
<ul class="nav nav-tabs">
	<li class="active"><a href="#setup-range" data-toggle="tab">Range Tanggal</a></li>
	<li><a href="#setup-refresh" data-toggle="tab">Refresh Time</a></li>
	<li><a href="#setup-staff" data-toggle="tab">Staff</a></li>
	<li><a href="#setup-owner" data-toggle="tab">Owner</a></li>
	<li><a href="#setup-ubahpassword" data-toggle="tab">Ubah Password</a></li>
</ul>
<div id="tabs-content"  class="tab-content">
	<div class="tab-pane in active" id="setup-range"><p>
		<form class="form-horizontal" id="form-range" disabled=true>
			<input type="text" name="task" value="UPDATE" placeholder="0" class="hidden">
			<div class="control-group">
				<label class="control-label" for="merah">Merah : kurang dari H - </label>
				<div class="controls">
					<input type="text" id="txt-merah" name="txt-merah" placeholder="0">
				</div>
			</div>

			<div class="control-group">
				<label class="control-label" for="kuning">Kuning : kurang dari H - </label>
				<div class="controls">
					<input type="text" id="txt-kuning" name="txt-kuning" placeholder="0">
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label" for="hijau">Hijau : kurang dari H - </label>
				<div class="controls">
					<input type="text" id="txt-hijau" name="txt-hijau" placeholder="0">
				</div>
			</div>
			
			<div class="form-actions">
				<button type="button" class="btn btn-primary" id="btn-simpanrange">Simpan</button>
			<button type="reset" class="btn" id="btn-resetrange">Reset</button>
			</div>
		</form>
	</p></div>
	<div class="tab-pane in" id="setup-refresh"><p>
		<form class="form-horizontal" id="form-refresh" disabled=true>
			<input type="text" name="task" value="UPDATE" placeholder="0" class="hidden">
			<div class="control-group">
				<label class="control-label left" for="refresh">Autorefresh layar tiap</label>
				<div class="controls">
					<input type="text" id="txt-refresh" name="txt-refresh" placeholder="0" size=3> Menit
				</div>
			</div>
			
			<div class="form-actions">
				<button type="button" class="btn btn-primary" id="btn-simpanrefresh">Simpan</button>
			<button type="reset" class="btn" id="btn-resetrefresh">Reset</button>
			</div>
		</form>
	</p></div>
	<div class="tab-pane in" id="setup-staff"><p>
		<form class="form-horizontal" id="form-staf">
			<input type="text" name="task" value="SAVE" placeholder="0" class="hidden">
			<input type="text" name="tipe" value="pic" placeholder="0" class="hidden">
			<input type="text" id="txt-stafid" name="txt-stafid" class="hidden">
			<div class="control-group">
				<label class="control-label left" for="nama">Nama</label>
				<div class="controls">
					<input type="text" id="txt-nama"  name="txt-nama" placeholder="Nama Staff" >
				</div>
			</div>
			<div class="control-group">
				<label class="control-label left" for="aktif">Aktif</label>
					<input type="checkbox" id="check-aktif" value="Y" name="check-aktif" >
				<div class="controls">
				</div>
			</div>
			
			<div class="form-actions">
				<button type="button" class="btn btn-primary" id="btn-simpanstaf">Simpan</button>
			<button type="reset" class="btn" id="btn-resetstaf">Reset</button>
			</div>
		</form>
		<div id="pager"></div>
		<table id="grid-staff" class="table table-striped table-bordered" ></table>
		<div id="pgrid-staff"></div>
	</p></div>
	<div class="tab-pane in" id="setup-owner"><p>
		<form class="form-horizontal" id="form-owner">
			<input type="text" name="task" value="SAVE" placeholder="0" class="hidden">
			<input type="text" name="tipe" value="owner" placeholder="0" class="hidden">
			<input type="text" id="txt-ownerid" name="txt-ownerid" class="hidden">
			<div class="control-group">
				<label class="control-label left" for="nama">Nama</label>
				<div class="controls">
					<input type="text" id="txt-ownernama"  name="txt-ownernama" placeholder="Nama owner" >
				</div>
			</div>
			<div class="control-group">
				<label class="control-label left" for="nama">Jenis</label>
				<div class="controls">
					<select id="cmb-jenis"  name="cmb-jenis" placeholder="Nama owner">
					<option value="BUMN" >BUMN</option>
					<option value="PEMERINTAH" >PEMERINTAH</option>
					<option value="SWASTA" >SWASTA</option>
					</select>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label left" for="owneraktif">Aktif</label>
				<div class="controls">
					<input type="checkbox" id="check-owneraktif" value="Y" checked=true name="check-owneraktif" >
				</div>
			</div>
			
			<div class="form-actions">
				<button type="button" class="btn btn-primary" id="btn-simpanowner">Simpan</button>
				<button type="reset" class="btn" id="btn-resetowner">Reset</button>
			</div>
		</form>
		<div id="pager"></div>
		<table id="grid-owner" class="table table-striped table-bordered" ></table>
		<div id="pgrid-owner"></div>
	</p></div>
	<div class="tab-pane in" id="setup-ubahpassword"><p>
		<form class="form-horizontal" id="form-ubahpassword" disabled=true>
			<input type="text" name="task" value="UPDATE" placeholder="0" class="hidden">
			<div class="control-group">
				<label class="control-label left" for="ubahpassword">New Password</label>
				<div class="controls">
					<input type="password" id="txt-ubahpassword" name="txt-ubahpassword" size=3>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label left" for="ubahpasswordrepeat">Repeat Password</label>
				<div class="controls">
					<input type="password" id="txt-ubahpasswordrepeat" name="txt-ubahpasswordrepeat" size=3>
				</div>
			</div>
			
			<div class="form-actions">
				<button type="button" class="btn btn-primary" id="btn-simpanubahpassword">Simpan</button>
			</div>
		</form>
	</p></div>
</div>